home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_residents.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  9.7 KB  |  302 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. static APTR resimoretext0,resimoretext1,resimoretext2a,resimoretext2b,resimoretext3;
  33.  
  34. static APTR ResiPool = NULL;
  35.  
  36. __asm __saveds LONG resilist_dspfunc(register __a2 char **array, register __a1 struct ResiEntry *resientry, register __a0 struct Hook *hook)
  37. {
  38.    if (resientry) {
  39.       *array++ = resientry->rt_address;
  40.       *array++ = resientry->rt_name;
  41.       *array++ = resientry->rt_pri;
  42.       *array++ = resientry->rt_idstring;
  43.       *array   = NULL;
  44.    } else {
  45.       *array++ = ESC "bAddress";
  46.       *array++ = ESC "bln_Name";
  47.       *array++ = ESC "brt_Pri";
  48.       *array++ = ESC "brt_IdString";
  49.       *array   = NULL;
  50.    }
  51.    return(0);
  52. }
  53.  
  54. struct Hook resilist_dsphook = {
  55.  {NULL, NULL},
  56.  (ULONG (* )())resilist_dspfunc,
  57.  NULL, NULL
  58. };
  59.  
  60. void FreeResidents (void)
  61. {
  62.     MyFreePoolStructs(&ResiPool, resitext, NULL, resilist);
  63. }
  64.  
  65. int GetResidents (struct ResiEntry **first) {
  66.    LONG     *resip, resi;
  67.    struct   ResiEntry    *resientry,*previous = NULL;
  68.    struct   ShortList {
  69.       struct   Resident    *sl_Resident;
  70.       struct   ShortList   *sl_Next;
  71.    };
  72.    struct   ShortList   *sl_Actual;
  73.  
  74.    int resicnt = 0;
  75.    *first = 0;
  76.  
  77.    if (!ResiPool) ResiPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  78.  
  79.    sl_Actual = (struct ShortList *) SysBase->KickTagPtr;
  80.  
  81.    if (clientstate) {
  82.       if (SendDaemon ("GetResiList")) {
  83.          while ((resientry = tbAllocPooled(ResiPool, sizeof(struct ResiEntry))) \
  84.            && (ReceiveDecodedEntry ((UBYTE *) resientry, sizeof (struct ResiEntry)))) {
  85.             IsHex (resientry->rt_address, (long *) &resientry->rt_adr);
  86.  
  87.             if (! *first)
  88.                *first = resientry;
  89.             if (previous)
  90.                previous->rt_next = resientry;
  91.  
  92.             resicnt++;
  93.             previous = resientry;
  94.          }
  95.       }
  96.    } else {
  97.       while ((sl_Actual) && (sl_Actual->sl_Resident) && (resientry = tbAllocPooled(ResiPool, sizeof(struct ResiEntry)))) {
  98.          if (! *first)
  99.             *first = resientry;
  100.          if (previous)
  101.             previous->rt_next = resientry;
  102.  
  103.          resientry->rt_adr = sl_Actual->sl_Resident;
  104.  
  105.          _sprintf (resientry->rt_address, HELL "$%08lx" DUNKEL, sl_Actual->sl_Resident);
  106.          strncpy (resientry->rt_name, nonetest (sl_Actual->sl_Resident->rt_Name), NODENAMELENGTH);
  107.          _sprintf (resientry->rt_pri, "%4ld", sl_Actual->sl_Resident->rt_Pri);
  108.          strncpy (resientry->rt_idstring, nonetest (sl_Actual->sl_Resident->rt_IdString), TEXTLENGTH);
  109.  
  110.          healstring (resientry->rt_name);
  111.          healstring (resientry->rt_idstring);
  112.          resicnt++;
  113.  
  114.          previous = resientry;
  115.          sl_Actual = (struct ShortList *) (0x7fffffff & (ULONG) sl_Actual->sl_Next);
  116.       }
  117.  
  118.       resip = (LONG *) FIRSTRESIDENT;
  119.  
  120.       while ((resi = *resip) && (resientry = tbAllocPooled(ResiPool, sizeof(struct ResiEntry)))) {
  121.          if (! *first)
  122.             *first = resientry;
  123.          if (previous)
  124.             previous->rt_next = resientry;
  125.  
  126.          /*HSMOD: must handle the case that has directly jump after each other */
  127.          while (0x80000000 & resi) {
  128.              resip = (long *) (0x7fffffff & resi);
  129.              resi = *resip;
  130.          }
  131.          resientry->rt_adr = (struct Resident *) resi;
  132.          _sprintf (resientry->rt_address, "$%08lx", resi);
  133.          strncpy (resientry->rt_name, nonetest (((struct Resident *) resi)->rt_Name), NODENAMELENGTH);
  134.          _sprintf (resientry->rt_pri, "%4ld", ((struct Resident *) resi)->rt_Pri);
  135.          strncpy (resientry->rt_idstring, nonetest (((struct Resident *) resi)->rt_IdString), TEXTLENGTH);
  136.  
  137.          healstring (resientry->rt_name);
  138.          healstring (resientry->rt_idstring);
  139.          resicnt++;
  140.  
  141.          previous = resientry;
  142.          resip += 1; /* plus 4 Bytes */
  143.       }
  144.    }
  145.    return (resicnt);
  146. }
  147.  
  148. void PrintResidents (char *filename) {
  149.    int   i=1;
  150.    BPTR  handle;
  151.    struct ResiEntry *entryp = NULL;
  152.  
  153.    handle = HandlePrintStart (filename);
  154.    if ((handle) && (PrintOneLine (handle, "\n  Address  Name                     Pri IdString\n\n"))) {
  155.       if (! WI_Residents) {
  156.          i = GetResidents (&entryp);
  157.       }
  158.       if (i) {
  159.          for (i=0;;i++) {
  160.             if (WI_Residents)
  161.                DoMethod (resilist,MUIM_List_GetEntry,i,&entryp);
  162.             if (!entryp) break;
  163.  
  164.             _sprintf (tmpstr2, " $%08lx %-23.23s %4s %s\n", entryp->rt_adr, entryp->rt_name, entryp->rt_pri, entryp->rt_idstring);
  165.             if (! (PrintOneLine (handle, tmpstr2)))
  166.                break;
  167.  
  168.             if (! WI_Residents)
  169.                entryp = entryp->rt_next;
  170.          }
  171.       }
  172.    }
  173.    HandlePrintStop();
  174. }
  175.  
  176. void ShowResidents (void) {
  177.    struct ResiEntry *resi;
  178.  
  179.    ApplicationSleep();
  180.    set (resilist,MUIA_List_Quiet,TRUE);
  181.    set (BT_ResiMore, MUIA_Disabled, TRUE);
  182.  
  183.    FreeResidents();
  184.    resicnt = GetResidents (&resi);
  185.  
  186.    while (resi) {
  187.       InsertBottomEntry (resilist, (APTR *) &resi);
  188.       resi = resi->rt_next;
  189.    }
  190.  
  191.    SetCountText (resicount, resicnt);
  192.    AwakeApplication();
  193.    set (resilist,MUIA_List_Quiet,FALSE);
  194. }
  195.  
  196. void SendResiList (void) {
  197.    struct   ResiEntry   *resi;
  198.  
  199.    FreeResidents();
  200.    resicnt = GetResidents (&resi);
  201.  
  202.    while (resi) {
  203.       SendEncodedEntry ((UBYTE *) resi, sizeof (struct ResiEntry));
  204.       resi = resi->rt_next;
  205.    }
  206.    FreeResidents();
  207. }
  208.  
  209. void GetResiMore (struct Resident *resi) {
  210.    unsigned char     *title = "RESIDENT: ";
  211.    struct   WinFree  *ptr;
  212.  
  213.    if (ptr = AllocWinFree()) {
  214.       ptr->wf_Window = (APTR) WindowObject,
  215.  
  216. //      MUIA_Window_SizeGadget, FALSE,
  217.       MUIA_HelpNode, ResidentsText,
  218.       MUIA_Window_ID, MakeDetailID('.','R','E','S'),
  219.       WindowContents, HGroup,
  220.          Child, VGroup, MUIA_Group_SameWidth, TRUE,
  221.             Child, MyLabel2 ("Name:"),
  222.             Child, MyLabel2 ("Address:\nPri:\nType:\nVersion:"),
  223.             Child, MyLabel2 ("IdString:"),
  224.          End,
  225.          Child, VGroup, MUIA_Group_SameWidth, TRUE,
  226.             Child, resimoretext0 = MyTextObject(),
  227.             Child, HGroup,
  228.                Child, resimoretext1 = MyTextObject(),
  229.                Child, VGroup,
  230.                   Child, MyLabel ("EndSkip:\nInit:"),
  231.                   Child, MyLabel ("Flags:"),
  232.                End,
  233.                Child, VGroup, MUIA_Group_SameWidth, TRUE,
  234.                   Child, resimoretext2a = MyTextObject(),
  235.                   Child, resimoretext2b = KeyButtonF ('b', resi->rt_Flags),
  236.                End,
  237.             End,
  238.             Child, resimoretext3 = MyTextObject(),
  239.          End,
  240.       End, End;
  241.  
  242.       if (ptr->wf_Window) {
  243.          MySetContents (resimoretext1, ESC "c$%08lx\n%ld\n%s\n%ld", resi, resi->rt_Pri, GetNodeType (resi->rt_Type), resi->rt_Version);
  244.          MySetContents (resimoretext2a, ESC "c$%08lx\n$%08lx", resi->rt_EndSkip, resi->rt_Init);
  245.  
  246.          HandleFlagsButtonPressed (resimoretext2b, ptr, "(RESIDENT)", "rt_Flags", resi->rt_Flags, (struct LongFlag *) &rtf_flags, NULL, 'b');
  247.          HandleWindowOpen (ptr, title, resi->rt_Name);
  248.          MySetContentsHealed (resimoretext0, resi->rt_Name);
  249.          MySetContentsHealed (resimoretext3, nonetest (resi->rt_IdString));
  250.          HandleWindowClose (ptr);
  251.       }
  252.    }
  253. }
  254.  
  255.  
  256. char residents_title[WINDOWTITLELEN];
  257.  
  258. void ResidentsWindow (BOOL state) {
  259.    if (state) {
  260.       if (WI_Residents) {
  261.          ShowResidents();
  262.       } else {
  263.          WI_Residents = WindowObject,
  264.          MUIA_Window_Title, MyGetWindowTitle (residents_title, "RESIDENTS"),
  265.          MUIA_HelpNode, ResidentsText,
  266.          MUIA_Window_ID, MakeListID('R','E','S','I'),
  267.          WindowContents, VGroup,
  268.             Child, resilist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3",&resilist_dsphook),
  269.             Child, MyBelowListview (&resitext, &resicount),
  270.             Child, MyVSpace(2),
  271.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  272.                Child, BT_ResiUpdate     = KeyButtonA (UpdateText,ID_RESIUPDATE),
  273.                Child, BT_ResiPrint      = KeyButtonA (PrintText ,ID_RESIPRINT),
  274.                Child, BT_ResiMore       = KeyButtonA (MoreText  ,ID_RESIMORE),
  275.                Child, BT_ResiExit       = KeyButtonA (ExitText  ,ID_RESIEXIT),
  276.             End,
  277.          End, End;
  278.  
  279.          DoMethod (AP_Scout,OM_ADDMEMBER,WI_Residents);
  280.          DoMethod (WI_Residents,MUIM_Window_SetCycleChain,resilist,BT_ResiUpdate,BT_ResiPrint,BT_ResiMore,BT_ResiExit,NULL);
  281.  
  282.          SetCloseRequest (WI_Residents,ID_RESIEXIT);
  283.          SetListActive (resilist,ID_RESILV_ACTIVE);
  284.          SetListviewDoubleClick (resilist,ID_RESIMORE);
  285.  
  286.          ShowResidents();
  287.  
  288.          SetWindowOpen (WI_Residents,resilist,ID_RESIEXIT);
  289.       }
  290.    } else if ((! state) && (WI_Residents)) {
  291.       SetWindowClose (WI_Residents,TRUE);
  292.  
  293.       FreeResidents();
  294.  
  295.       DoMethod (AP_Scout,OM_REMMEMBER,WI_Residents);
  296.       MUI_DisposeObject (WI_Residents);
  297.       WI_Residents = NULL;
  298.       resilist = NULL;
  299.    }
  300. }
  301.  
  302.